#include "Teacher.h"
#include<stdio.h>
#include "Student.h"
#include<string.h>
#include<stdbool.h>
void PrintTeacher(const Teach *t)
{   //结构体指针访问变量用箭头
    printf("名字：%s 年龄：%d\n",t->name,t->age);
    
    for (int i = 0; i < t->size; i++)
    {   printf("tch");
        PrintStu(t->s+i);
    }
    
}
void InitTeacher(Teach*t,const char*name,int age,const int size)
{
    strcpy(t->name,name);
    t->age=age;
    t->size=size;
}
void RemoveStu(Teach *t, const char *name)
{
    for (int i = 0; i < t->size; i++)
    {
        if(strcmp(t->s[i].name,name)==0)
        {
            ReoveByIndex(t,i);
            i--;
            
        }
    }
    

}

void InsetStu(Teach *t, const char *name, const int id,const int age,const double score)
{   
    for (int i=0; i < t->size; i++)
    {   if (t->s[i].id==0)
    {
        t->s[i].age=age;
        strcpy(t->s[i].name,name);
        t->s[i].score=score;
        t->s[i].id=id;
        break;
    }
    
        
    }
    
       
}
//按照下标删除数组元素
void ReoveByIndex(Teach * t,const int index)
{
    for(int i=index;i<t->size-1;i++)
    {
        t->s[i]=t->s[i+1];
    }
    t->size--;
}

Stu * FindeFirstStu(Teach*t,void *value,bool(*p)(Stu*,void*))
{
    for (int i = 0; i < t->size; i++)
    {
        if(p(t->s+i,value)==true)
        {
            return t->s+i;
        }
        
    }
    
    return NULL;
    
}
